package com.oocl.webmvc.service.impl;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.oocl.webmvc.dao.CustomerDao;
import com.oocl.webmvc.db.CustomerDB;
import com.oocl.webmvc.pojo.Customer;
import com.oocl.webmvc.service.CustomerService;

/**
 * @description: 增加了同步锁，
 * @author  XIEMI2
 * @date Aug 7, 2017 4:23:28 PM
 * @version 2.0
 * 
 */
@Service
public class CustomerServiceImpl implements CustomerService{

	@Resource
	private CustomerDao customerDao;
	
	public CustomerServiceImpl() {
		super();
		System.out.println("CustomerServiceImpl....start...customerDao....");
	}

	@Override
	public Customer addCustomer(Customer cust) {
		synchronized (customerDao) {
			customerDao.addCustomer(cust);
			return cust;
		}
	}

	@Override
	public List<Customer> findAllCustomers() {
		return customerDao.findAllCustomers();
	}

	@Override
	public String delCustomer(String customerId) {
		synchronized (customerDao) {
			customerDao.delCustomer(customerId);
		}
		return "{}";
	}

	/**
	 *  如果下面用 remove ， 坐标会变化的
	 */
	@Override
	public Customer updateCustomer(Customer cust) {
		synchronized (customerDao) {
			customerDao.updateCustomer(cust);
			return cust;
		}
	}
}


